package com.aipanda.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * 产品基本参数组类|memo[产品基本参数值是唯一性的,如果值是唯一性的,应该放在产品基本参数组类]<br/>
 * ---商品管理->商品参数
 * @msg.memo 商品最基础的参数属性,产品具备的特征
 * @param 	name 			名称 
 * @param 	productCategory 产品种类  [多对一关系]
 * @param 	parameters 		参数组  [一对多关系]
 * @author wanyuxiang
 *
 */
@Entity
@Table(name = "aipanda_parameter_group")
public class ParameterGroup extends OrderEntity {
	private static final long serialVersionUID = 192003501177471941L;
	private String name;
	private ProductCategory productCategory;
	private List<Parameter> parameters = new ArrayList<Parameter>();

	@JsonProperty
	@NotEmpty
	@Length(max = 255)
	@Column(nullable = false)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@NotNull
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name="product_category",nullable = false)
	public ProductCategory getProductCategory() {
		return this.productCategory;
	}

	public void setProductCategory(ProductCategory productCategory) {
		this.productCategory = productCategory;
	}

	@JsonProperty
	@Valid
	@NotEmpty
	@OneToMany(mappedBy = "parameterGroup", fetch = FetchType.LAZY, cascade = {CascadeType.ALL }, orphanRemoval = true)
	@OrderBy("order asc")
	public List<Parameter> getParameters() {
		return this.parameters;
	}

	public void setParameters(List<Parameter> parameters) {
		this.parameters = parameters;
	}
}
